package main

import (
	_ "gf_api/boot"
	_ "gf_api/router"
	"github.com/gogf/gf/errors/gerror"
	"github.com/gogf/gf/net/ghttp"

	"github.com/gogf/gf/frame/g"
)


func MiddlewareErrorHandler(r *ghttp.Request) {
	r.Middleware.Next()
<<<<<<< HEAD
	//println(err)
	if err := r.GetError(); err != nil {
		r.Response.ClearBuffer()
		println(r.Response.ResponseWriter.Status)
		r.Response.Writef("%+v", err)
		//g.Map{}
=======
	if err := r.GetError(); err != nil {
		// 返回固定的友好信息
		r.Response.ClearBuffer()
		returnData := g.Map{
			"code": gerror.Code(err),
			"data": r.GetError().Error(),
		}
		g.Log().Error( returnData) // 记录到自定义错误日志文件
		r.Response.Writeln(returnData)
>>>>>>> 7e1d95c5251e919542c8dd673de186a71fd1131e
	}
	//println(r.GetError().)
}

func main() {
	app := g.Server()
	app.Use(MiddlewareErrorHandler)
	app.Run()
}
